<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>微信支付</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=0">
    <meta name="format-detection" content="telephone=no">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
	<script src="../../js/jquery-1.7.2.min.js"></script>
	<script src="../../js/wxutil/jssdk.js"></script>
	<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head>
<body>
	<div align="center" id="loading">
		<img src="../../images/load.gif"/>
	</div>
</body>
<script type="text/javascript">
	var openid = getQuery('openid'), appid = 'wx3333187e39e801e8';
	// 获取jssdk配置
	getConfig(appid, function(res) {
		if (res) {
			prepay(openid);
		} else {
			$('#loading').hide();
		}
	});

	// 预支付
	function prepay(openid) {
		$.ajax({
	        url: path + '/ocrWxpay/kpay',
	        type: 'POST',
	        data: {
	        	openid: openid, totalFee: 300, appid: appid, _openid: getQuery('_openid')
	        },
	        dataType: 'JSON',
	        success: function(data) {
	        	if (data.success) {
	        		var result = data.result;
	        		console.log('result', result);
	        		// 此处替换=，否则数据被截断
	        		result['package'] = result['package'].replace('=', '$');
	        		var url = '/pages/userinfo/userinfo?payData=' + JSON.stringify(result);
	        		wx.miniProgram.navigateTo({ url: url });
	        	} else {
	        		alert(data.message);
	        	}
	        },
	        complete: function() {
	        	$('#loading').hide();
	        }
		});
	}
</script>
</html>